package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.phonehelp.ShieldRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/**
 * 金盾风险分
 *
 * @author renzhanzheng
 */

public class ShieldScoreParse extends ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     * 金盾分(风险分、欺诈分)
     *
     * @param model
     * @throws IOException
     * @throws InterruptedException
     * @return
     */

    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        ShieldRecord obj = (ShieldRecord)model;

        StringBuilder sb = getBaseInfo(obj, successful);
        //idcard
        sb.append(obj.getIdCard() == null ? "" : obj.getIdCard()).append(CRT001);
        //sid
        sb.append(obj.getSid() == null ? "" : obj.getSid()).append(CRT001);
        //信用风险等级V2
        sb.append(obj.getCreditv2() == null ? "" : obj.getCreditv2()).append(CRT001);
        //信用风险等级V2
        sb.append(obj.getFraudv2() == null ? "" : obj.getFraudv2()).append(CRT001);
        StringBuilder txSb = getBaseInfo(obj);
        key.set(getKey());
        val.set((sb.toString() + txSb).replace("\n", " ").replace("\r", " "));
        context.write(key, val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_shield_score_inc";
    }

    @Override
    public String getType() {
        return RecordType.PHONE_SHIELD_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "金盾分(风险分、欺诈分)";
    }
}
